package com.jy.adscm.operation.purchase.mapper.mysql;

import com.jy.adscm.operation.config.MyPage;
import com.jy.adscm.operation.purchase.bean.BomAddSupplier;
import com.jy.adscm.operation.purchase.bean.Machinetype;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 机器型号bom对应数量的配置表 Mapper 接口
 * </p>
 *
 * @author lzf
 * @since 2019-05-05
 */
public interface MachinetypeMapper extends BaseMapper<Machinetype> {
    List<Machinetype> queryConfig(@Param("currentPage") Integer currentPage,
                                  @Param("pageSize") Integer pageSize,
                                  @Param("key") String key,
                                  @Param("sortBy") String sortBy,
                                  @Param("code")String code);

    Integer queryCount( @Param("key") String key,@Param("code")String code);

    @Select("SELECT\n" +
            "\n" +
            "a.CODE,\n" +
            "a.NAME,\n" +
            "a.specification,\n" +
            "a.texture,\n" +
            "a.parentId5,\n" +
            "a.rank,\n" +
            "a.figureNum,\n" +
            "a.parentId2,\n" +
            "a.parentId3,\n" +
            "a.parentId4,\n" +
            "a.parentId,\n" +
            "a.nums,\n" +
            "a.parentId1,\n" +
            "a.NO,\n" +
            "a.bomName,\n" +
            "a.machineType,\n" +
            "b.miniPurchase,\n" +
            "b.predate,\n" +
            "b.price,\n" +
            "c.makeInvoiceType,\n" +
            "c.paymentMethod,\n" +
            "c.transporttationMethod,\n" +
            "b.firstNums,\n" +
            "b.bid,\n" +
            "b.sid,\n" +
            "c.paymentPeriod, c.advanceSum,\n" +
            "c.letter,\n" +
            "c.name as supplierNAME,\n" +
            "c.contacts,\n" +
            "c.address,\n" +
            "c.fax,\n" +
            "c.phone,\n" +
            "c.email,\n" +
            "c.openingBank,\n" +
            "c.account,\n" +
            "c.tax,\n" +
            "c.qualityMoney,\n" +
            "c.businessLicensePhoto,\n" +
            "c.taxPhoto,\n" +
            "c.treatmentCorrelation,\n" +
            "c.otherQualification,\n" +
            "c.siteSize,\n" +
            "c.peopleNums,\n" +
            "c.equipmentNums,\n" +
            "c.property,\n" +
            "c.kernelProduct,\n" +
            "c.cruxCraft,\n" +
            "c.isDesignAbility,b.bomNums,b.MaterialLeadTime as MaterialLeadTimes\n" +
            "\n" +
            " FROM  purchasebom a LEFT JOIN bomandsupplier b on a.id=b.bid LEFT JOIN supplier c ON b.sid = c.id " +
            "WHERE b.bid is not NULL AND a.machineType=#{type} GROUP BY a.bomName ,a.specification ")
    List<BomAddSupplier> queryByType(@Param("type") String type);

    @Select("SELECT a.REMAININGNUMS FROM jqyl_material a  WHERE a.RESOURCENAME=#{materialId}")
    Integer queryInventoryNums(@Param("materialId")Long materialId);



    @Select("SELECT\n" +
            "\ta.*,\n" +
            "\tb.NAME AS bomName\n" +
            "FROM\n" +
            "\tmachinetype a\n" +
            "\tLEFT JOIN bom b ON a.bid = b.id\n" +
            "WHERE\n" +
            "\ta.type = #{code}\n" +
            "\tAND a.parentId = #{pid} \n" +
            "ORDER BY\n" +
            "\ta.rank DESC")
    List<Machinetype> queryByPid(@Param("pid") Long pid,@Param("code")String code);
}
